
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:zfth/api/RepairApi.dart';
import 'package:zfth/api/StateApi.dart';
import '../../components/list/LCellListLogic.dart';
import '../../components/list/LCellListPage.dart';
import '../../utils/Settings.dart';
import '../../utils/Utils.dart';




class AllEqListPage extends StatefulWidget{

  const AllEqListPage({super.key});

  @override
  State<AllEqListPage> createState() =>AllEqListPageState();

}

class AllEqListPageState extends State<AllEqListPage> with AutomaticKeepAliveClientMixin{


  late final LCellListLogic cellListLogic;

  bool keepAlive = true;

  List queryFormAttributes = [
    {'field':'deviceRoom','label':'电房','component':'select','dictCode':Settings.dictCodes["配电室"],'condition':'eq'},
    {'field':'deviceNo','label':'采集终端','component':'select','dictCode':Settings.dictCodes["设备"],'condition':'eq'},

  ];

  String tag = "allEqList";
  @override
  void initState() {
    cellListLogic = Get.put(LCellListLogic(),tag: tag);
    cellListLogic.init(
        axiosUrl: StateApi.stateViewListUrl,
        buildItemWidget: buildListItem,
        queryFormAttributes:queryFormAttributes,
        dictCodes:'${Settings.dictCodes["区域"]},${Settings.dictCodes["配电室"]},${Settings.dictCodes["设备"]},${Settings.dictCodes["设备类型"]}',
        initOrder:[{"field":"b.device_type","val":"asc"},{"field":"a.device_no","val":"asc"}],
        tag: tag
    );
    super.initState();
  }

  @override
  void dispose() {
    Get.delete<LCellListLogic>(tag: tag);
    super.dispose();
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => keepAlive;







  Widget buildListItem(item){
    return GestureDetector(
      onTap: () {
      },
      child: Card(
          elevation: 0.2,
          margin: const EdgeInsets.fromLTRB(10, 10, 10, 0),
          child: Stack(
            children: [
              IntrinsicHeight(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Expanded(
                        child:Padding(
                          padding: const EdgeInsets.only(top: 10,left: 10),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [

                              Text(Utils.filterDictText(Settings.dictCodes["区域"],{},'${item["deviceRegion"]}'),style: const TextStyle(color: Colors.black38),),
                              // const SizedBox(width: 4,),
                              // Text(Utils.filterDictText(Settings.dictCodes["配电室"],{},'${item["deviceRoom"]}'),style: const TextStyle(color: Colors.black38),),
                            ],
                          ),
                        )

                    ),
                    Expanded(
                        child:Padding(
                          padding: const EdgeInsets.only(left: 10,top: 0,bottom: 0,right: 0),

                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              Text("${item["deviceName"]}"),
                              const SizedBox(width: 4,),
                              Text(Utils.filterDictText(Settings.dictCodes["设备类型"],{},'${item["deviceType"]}'),style: const TextStyle(color: Colors.black38),),

                            ],
                          ),
                        )

                    ),
                    Expanded(
                        child:Padding(
                            padding: const EdgeInsets.only(left: 10,top: 0,bottom: 0,right: 0),
                            child: Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: [
                                  Image.asset("images/bianhao.png",width: 16,height: 16,fit:BoxFit.contain ,),
                                  const SizedBox(width: 4,),
                                  Text("${item["deviceNo"]}",style: const TextStyle(color: Colors.black38)),

                                  Visibility(
                                      visible: item['lineState']=='1',
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.start,
                                        children: [
                                          Image.asset("images/zaxian.png",width: 20,height: 20,fit:BoxFit.contain ,),
                                          const Text("在线",style: TextStyle(color: Colors.black38)),
                                        ],
                                      )
                                  ),
                                  Visibility(
                                      visible: item['lineState']=='0',
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.start,
                                        children: [
                                          Image.asset("images/lixian.png",width: 20,height: 20,fit:BoxFit.contain ,),
                                          const Text("离线",style: TextStyle(color: Colors.black38)),
                                        ],
                                      )
                                  ),


                                  const SizedBox(width: 14,),
                                  Visibility(
                                    visible: item['alarmState']=='1',
                                    child: Image.asset("images/baojing.png",width: 20,height: 20,fit:BoxFit.contain ,),
                                  ),



                                ]


                            )
                        )
                    ),

                  ],


                ),
              ),

            ],
          )

      ),
    );
  }


  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      backgroundColor: Settings.backgroundColor,
      appBar: AppBar(
        title: const Text("终端列表"),
        centerTitle: true,
        elevation: 0,
      ),
      body: LCellListPage(tag:tag),

    );
  }

}